Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler-core): more hoisting optimizations #276

Merged
merged 4 commits into from
Oct 15, 2019
Merged

feat(compiler-core): more hoisting optimizations #276

merged 4 commits into from
Oct 15, 2019

Conversation

HcySunYang
Copy link
Member

@HcySunYang HcySunYang commented Oct 14, 2019

This PR enhances hoisting optimization:

1. Dynamic attribute with static value:

<div><span :foo="0"></span></div>

Before:

import { createVNode, createBlock, openBlock } from "vue"

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    createVNode("span", { foo: 0 }, null, 8 /* PROPS */, ["foo"])
  ]))
}

Now:

import { createVNode, createBlock, openBlock } from "vue"

const _hoisted_1 = createVNode("span", { foo: 0 })

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    _hoisted_1
  ]))
}

2. Static interpolation:

<div><span>{{ 1 + 2 }}</span></div>

Before:

import { toString, createVNode, createBlock, openBlock } from "vue"

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    createVNode("span", null, toString(1 + 2), 1 /* TEXT */)
  ]))
}

Now:

import { toString, createVNode, createBlock, openBlock } from "vue"
// Maybe patchFlag can be removed.
const _hoisted_1 = createVNode("span", null, toString(1 + 2), 1 /* TEXT */)

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    _hoisted_1
  ]))
}

3. Write inline styles/class for better performance:

<div><span :class="{ foo: true }">{{ bar }}</span></div>

Before:

import { toString, createVNode, createBlock, openBlock } from "vue"

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    createVNode("span", { class: { foo: true }}, toString(_ctx.bar), 3 /* TEXT, CLASS */)
  ]))
}

Now:

import { toString, createVNode, createBlock, openBlock } from "vue"

const _hoisted_1 = { class: { foo: true }}

export default function render() {
  const _ctx = this
  return (openBlock(), createBlock("div", null, [
    createVNode("span", _hoisted_1, toString(_ctx.bar), 1 /* TEXT */)
  ]))
}

This can avoid class being patched.

If there is a more suitable implementation, or if this feature does not match the plan, or for other reasons, then this PR can be closed at any time, thanks

@HcySunYang

This comment has been minimized.

@yyx990803 yyx990803 merged commit 68a3879 into vuejs:master Oct 15, 2019
@vue-bot
Copy link
Contributor

vue-bot commented Oct 15, 2019

Hey @HcySunYang, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

yyx990803 added a commit that referenced this pull request Oct 15, 2019
@yyx990803
Copy link
Member

Great work!

yyx990803 pushed a commit that referenced this pull request Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants